Change rebooting specification so that we can have domains crash and stay
authoremellor@ewan <emellor@ewan>
Fri, 30 Sep 2005 12:59:28 +0000 (13:59 +0100)
committeremellor@ewan <emellor@ewan>
Fri, 30 Sep 2005 12:59:28 +0000 (13:59 +0100)
around to be debugged, for example.

Fix problem in XendDomainInfo.eventChannel caused by a mis-merge.

Signed-off-by: Ewan Mellor <ewan@xensource.com>
tools/examples/xmexample.vmx
tools/examples/xmexample1
tools/examples/xmexample2
tools/examples/xmexample3
tools/python/xen/xend/XendDomainInfo.py

index 4de6aacbf7ffc395c9237f79c18da6f9de729955..9b1ca8f221dd809921fa9afa66b5efd49628f1cb 100644 (file)
@@ -48,12 +48,36 @@ vcpus=1
 disk = [ 'file:/var/images/min-el3-i386.img,ioemu:hda,w' ]
 
 #----------------------------------------------------------------------------
-# Set according to whether you want the domain restarted when it exits.
-# The default is 'onreboot', which restarts the domain when it shuts down
-# with exit code reboot.
-# Other values are 'always', and 'never'.
-
-#restart = 'onreboot'
+# Configure the behaviour when a domain exits.  There are three 'reasons'
+# for a domain to stop: poweroff, reboot, and crash.  For each of these you
+# may specify "destroy", meaning that the domain is cleaned up as normal,
+# "restart", meaning that a new domain is started in place of the old one, or
+# "preserve", meaning that no clean-up is done until the domain is manually
+# destroyed (using xm destroy, for example).
+#
+# The default is
+#
+#   on_poweroff = 'destroy'
+#   on_reboot   = 'restart'
+#   on_crash    = 'restart'
+#
+# For backwards compatibility we also support the deprecated option restart
+#
+# restart = 'onreboot' means on_poweroff = 'destroy'
+#                            on_reboot   = 'restart'
+#                            on_crash    = 'destroy'
+#
+# restart = 'always'   means on_poweroff = 'restart'
+#                            on_reboot   = 'restart'
+#                            on_crash    = 'restart'
+#
+# restart = 'never'    means on_poweroff = 'destroy'
+#                            on_reboot   = 'destroy'
+#                            on_crash    = 'destroy'
+
+#on_poweroff = 'destroy'
+#on_reboot   = 'restart'
+#on_crash    = 'restart'
 
 #============================================================================
 
index b3aecf854e8167929dbdcbb2c704e52c80a8c999..bd2e70d9a2eec49746fdfb21a743607d235b5d2c 100644 (file)
@@ -91,11 +91,35 @@ root = "/dev/hda1 ro"
 extra = "4"
 
 #----------------------------------------------------------------------------
-# Set according to whether you want the domain restarted when it exits.
-# The default is 'onreboot', which restarts the domain when it shuts down
-# with exit code reboot.
-# Other values are 'always', and 'never'.
-
-#restart = 'onreboot'
+# Configure the behaviour when a domain exits.  There are three 'reasons'
+# for a domain to stop: poweroff, reboot, and crash.  For each of these you
+# may specify "destroy", meaning that the domain is cleaned up as normal,
+# "restart", meaning that a new domain is started in place of the old one, or
+# "preserve", meaning that no clean-up is done until the domain is manually
+# destroyed (using xm destroy, for example).
+#
+# The default is
+#
+#   on_poweroff = 'destroy'
+#   on_reboot   = 'restart'
+#   on_crash    = 'restart'
+#
+# For backwards compatibility we also support the deprecated option restart
+#
+# restart = 'onreboot' means on_poweroff = 'destroy'
+#                            on_reboot   = 'restart'
+#                            on_crash    = 'destroy'
+#
+# restart = 'always'   means on_poweroff = 'restart'
+#                            on_reboot   = 'restart'
+#                            on_crash    = 'restart'
+#
+# restart = 'never'    means on_poweroff = 'destroy'
+#                            on_reboot   = 'destroy'
+#                            on_crash    = 'destroy'
+
+#on_poweroff = 'destroy'
+#on_reboot   = 'restart'
+#on_crash    = 'restart'
 
 #============================================================================
index 0acf32bbeccd800cf107681fc3359c1089fe5d9f..fb7bd05fc567241c7951a4e3bff455d5d4d6b225 100644 (file)
@@ -127,11 +127,35 @@ root = "/dev/sda1 ro"
 extra = "4 VMID=%d usr=/dev/sda6" % vmid
 
 #----------------------------------------------------------------------------
-# Set according to whether you want the domain restarted when it exits.
-# The default is 'onreboot', which restarts the domain when it shuts down
-# with exit code reboot.
-# Other values are 'always', and 'never'.
+# Configure the behaviour when a domain exits.  There are three 'reasons'
+# for a domain to stop: poweroff, reboot, and crash.  For each of these you
+# may specify "destroy", meaning that the domain is cleaned up as normal,
+# "restart", meaning that a new domain is started in place of the old one, or
+# "preserve", meaning that no clean-up is done until the domain is manually
+# destroyed (using xm destroy, for example).
+#
+# The default is
+#
+#   on_poweroff = 'destroy'
+#   on_reboot   = 'restart'
+#   on_crash    = 'restart'
+#
+# For backwards compatibility we also support the deprecated option restart
+#
+# restart = 'onreboot' means on_poweroff = 'destroy'
+#                            on_reboot   = 'restart'
+#                            on_crash    = 'destroy'
+#
+# restart = 'always'   means on_poweroff = 'restart'
+#                            on_reboot   = 'restart'
+#                            on_crash    = 'restart'
+#
+# restart = 'never'    means on_poweroff = 'destroy'
+#                            on_reboot   = 'destroy'
+#                            on_crash    = 'destroy'
 
-#restart = 'onreboot'
+#on_poweroff = 'destroy'
+#on_reboot   = 'restart'
+#on_crash    = 'restart'
 
 #============================================================================
index 1fa80cb2e3b036689b19958192c7a3cf0304bc99..e0e1775589cf011d3d013db6fa6e9455a65f7191 100644 (file)
@@ -124,11 +124,35 @@ root = "/dev/hda1 ro"
 extra = "4 VMID=%d" % vmid
 
 #----------------------------------------------------------------------------
-# Set according to whether you want the domain restarted when it exits.
-# The default is 'onreboot', which restarts the domain when it shuts down
-# with exit code reboot.
-# Other values are 'always', and 'never'.
+# Configure the behaviour when a domain exits.  There are three 'reasons'
+# for a domain to stop: poweroff, reboot, and crash.  For each of these you
+# may specify "destroy", meaning that the domain is cleaned up as normal,
+# "restart", meaning that a new domain is started in place of the old one, or
+# "preserve", meaning that no clean-up is done until the domain is manually
+# destroyed (using xm destroy, for example).
+#
+# The default is
+#
+#   on_poweroff = 'destroy'
+#   on_reboot   = 'restart'
+#   on_crash    = 'restart'
+#
+# For backwards compatibility we also support the deprecated option restart
+#
+# restart = 'onreboot' means on_poweroff = 'destroy'
+#                            on_reboot   = 'restart'
+#                            on_crash    = 'destroy'
+#
+# restart = 'always'   means on_poweroff = 'restart'
+#                            on_reboot   = 'restart'
+#                            on_crash    = 'restart'
+#
+# restart = 'never'    means on_poweroff = 'destroy'
+#                            on_reboot   = 'destroy'
+#                            on_crash    = 'destroy'
 
-#restart = 'onreboot'
+#on_poweroff = 'destroy'
+#on_reboot   = 'restart'
+#on_crash    = 'restart'
 
 #============================================================================
index 820bae27fa6b9f469713282d9b4bf5b62a5905dd..dac0affce61e8f3fa24e1a9609ccc79e2366128f 100644 (file)
@@ -67,14 +67,10 @@ shutdown_reasons = {
     DOMAIN_CRASH   : "crash",
     }
 
-RESTART_ALWAYS   = 'always'
-RESTART_ONREBOOT = 'onreboot'
-RESTART_NEVER    = 'never'
-
 restart_modes = [
-    RESTART_ALWAYS,
-    RESTART_ONREBOOT,
-    RESTART_NEVER,
+    "restart",
+    "destroy",
+    "preserve"
     ]
 
 STATE_VM_OK         = "ok"
@@ -112,7 +108,10 @@ ROUNDTRIPPING_CONFIG_ENTRIES = [
         ('name',         str),
         ('ssidref',      int),
         ('cpu_weight',   float),
-        ('bootloader',   str)
+        ('bootloader',   str),
+        ('on_poweroff',  str),
+        ('on_reboot',    str),
+        ('on_crash',     str)
     ]
 
 
@@ -135,8 +134,6 @@ def restore(config):
     vm.storeVmDetails()
     vm.configure()
     vm.create_channel()
-#         vm.exportToDB()
-#    vm.refreshShutdown()
     vm.storeDomDetails()
     return vm
 
@@ -272,7 +269,6 @@ class XendDomainInfo:
         result['maxmem']       = get_cfg('maxmem',     int)
         result['maxmem_kb']    = get_cfg('maxmem_kb',  int)
         result['cpu']          = get_cfg('cpu',        int)
-        result['restart_mode'] = get_cfg('restart')
         result['image']        = get_cfg('image')
 
         try:
@@ -295,6 +291,30 @@ class XendDomainInfo:
             c = sxp.child0(d)
             result['device'].append((sxp.name(c), c))
 
+        # Configuration option "restart" is deprecated.  Parse it, but
+        # let on_xyz override it if they are present.
+        restart = get_cfg('restart')
+        if restart:
+            def handle_restart(event, val):
+                if not event in result:
+                    result[event] = val
+
+            if restart == "onreboot":
+                handle_restart('on_poweroff', 'destroy')
+                handle_restart('on_reboot',   'restart')
+                handle_restart('on_crash',    'destroy')
+            elif restart == "always":
+                handle_restart('on_poweroff', 'restart')
+                handle_restart('on_reboot',   'restart')
+                handle_restart('on_crash',    'restart')
+            elif restart == "never":
+                handle_restart('on_poweroff', 'destroy')
+                handle_restart('on_reboot',   'destroy')
+                handle_restart('on_crash',    'destroy')
+            else:
+                log.warn("Ignoring malformed and deprecated config option "
+                         "restart = %s", restart)
+
         log.debug("parseConfig: result is %s" % str(result))
         return result
 
@@ -347,7 +367,9 @@ class XendDomainInfo:
                 self.info[name] = val
 
         params = (("name", str),
-                  ("restart_mode", str),
+                  ("on_poweroff",  str),
+                  ("on_reboot",    str),
+                  ("on_crash",     str),
                   ("image",        str),
                   ("start_time", float))
 
@@ -375,7 +397,9 @@ class XendDomainInfo:
         try:
             defaultInfo('name',         lambda: "Domain-%d" % self.domid)
             defaultInfo('ssidref',      lambda: 0)
-            defaultInfo('restart_mode', lambda: RESTART_ONREBOOT)
+            defaultInfo('on_poweroff',  lambda: "destroy")
+            defaultInfo('on_reboot',    lambda: "restart")
+            defaultInfo('on_crash',     lambda: "restart")
             defaultInfo('cpu',          lambda: None)
             defaultInfo('cpu_weight',   lambda: 1.0)
             defaultInfo('bootloader',   lambda: None)
@@ -459,9 +483,10 @@ class XendDomainInfo:
                     raise VmError('invalid device (%s, %s)' %
                                   (str(n), str(c)))
 
-            if self.info['restart_mode'] not in restart_modes:
-                raise VmError('invalid restart mode: ' +
-                              str(self.info['restart_mode']))
+            for event in ['on_poweroff', 'on_reboot', 'on_crash']:
+                if self.info[event] not in restart_modes:
+                    raise VmError('invalid restart event: %s = %s' %
+                                  (event, str(self.info[event])))
 
             if 'cpumap' not in self.info:
                 if [self.info['vcpus'] == 1]:
@@ -509,14 +534,14 @@ class XendDomainInfo:
         to_store = {
             'uuid':               self.uuid,
 
-            # !!!
+            # XXX
             'memory/target':      str(self.info['memory_KiB'])
             }
 
         if self.infoIsSet('image'):
             to_store['image'] = sxp.to_string(self.info['image'])
 
-        for k in ['name', 'ssidref', 'restart_mode']:
+        for k in ['name', 'ssidref', 'on_poweroff', 'on_reboot', 'on_crash']:
             if self.infoIsSet(k):
                 to_store[k] = str(self.info[k])
 
@@ -625,7 +650,7 @@ class XendDomainInfo:
                 if xroot.get_enable_dump():
                     self.dumpCore()
 
-                restart_reason = 'crashed'
+                restart_reason = 'crash'
 
             elif xeninfo['shutdown']:
                 reason = shutdown_reason(xeninfo['shutdown_reason'])
@@ -682,10 +707,16 @@ class XendDomainInfo:
 
 
     def maybeRestart(self, reason):
-        if self.restart_needed(reason):
-            self.restart()
-        else:
-            self.destroy()
+        # Dispatch to the correct method based upon the configured on_{reason}
+        # behaviour.
+        {"destroy"  : self.destroy,
+         "restart"  : self.restart,
+         "preserve" : self.preserve}[self.info['on_' + reason]]()
+
+
+    def preserve(self):
+        log.info("Preserving dead domain %s (%d).", self.info['name'],
+                 self.domid)
 
 
     def dumpCore(self):
@@ -998,7 +1029,6 @@ class XendDomainInfo:
         """
         self.create_channel()
         self.image.createImage()
-#        !!! self.exportToDB()
         IntroduceDomain(self.domid, self.store_mfn,
                         self.store_channel.port1, self.dompath)
         self.configure_vcpus()
@@ -1091,7 +1121,6 @@ class XendDomainInfo:
                 # The port is not yet set, i.e. the channel has not yet been
                 # created.
                 pass
-        ret = channel.eventChannel(0, self.domid, port1=port, port2=0)
 
         # Stale port information from above causes an Invalid Argument to be
         # thrown by the eventChannel call below.  To recover, we throw away